package info.xiao.dataStructrue.array;

/**
 * @Classname MaxRotateFunction
 * @Description 旋转函数
 * @href https://leetcode.cn/problems/rotate-function/
 * @Date 2023/3/15 9:38
 * @Created by 晓龙Oba
 */
public class MaxRotateFunction {

    public static void main(String[] args) {
        int[] nums = {4, 3, 2, 6};
        int maxValue = maxRotateFunction(nums);
        System.out.println(maxValue);
    }

    private static int maxRotateFunction(int[] nums) {
        int maxValue = 0;
        int sum = 0;
        int tmp = 0;
        // 从第一个数组开始算
        for (int i = 0; i < nums.length; i++) {
            maxValue += nums[i] * i;
            tmp = maxValue;
            sum += nums[i];
        }
        for (int i = 1; i < nums.length; i++) {
            int flag = sum - nums[nums.length - i];
            int mark = (nums[nums.length - i] * (nums.length - 1));
            System.out.println(flag + ":" + mark);
            tmp = tmp + (sum - nums[nums.length - i]) - (nums[nums.length - i] * (nums.length - 1));
            maxValue = maxValue > tmp ? maxValue : tmp;
        }

        return maxValue;
    }
}
